<?php


namespace App\Services;


use App\Models\ClassStudent;
use App\Models\SchoolClassCourse;
use App\Models\Users;

class StudentEvaluationService extends BaseService
{
    /**
     * 获取用户评价列表
     * @return
     */
    public function listStudentWork($name,$class_grades_id,$course_section_id,$page,$limit,$sort,$order) {
        $query = ClassStudent::leftJoin('users', 'users.id', '=', 'class_students.users_id')
            ->leftJoin('student_works', function ($join) use ($course_section_id) {
                $join->on('student_works.users_id', '=', 'class_students.users_id')
                    ->where('student_works.course_section_id', '=', $course_section_id);
            })
            ->select('users.id','users.name','users.age','users.sex','student_works.work_name','student_works.work_file','student_works.score','student_works.created_at');
        $query->where('class_students.class_grades_id',$class_grades_id);
        if(!empty($name)){
            $query->where('users.name','like',"%$name%");
        }

        return $query->orderBy($sort,$order)->paginate($limit, ['*'], 'page', $page);
    }
    /**
     * 获取用户评价列表
     * @return
     */
    public function listClass($school_id,$course_id) {
        $query = SchoolClassCourse::leftJoin('class_grades', 'class_grades.id', '=', 'school_class_courses.class_grades_id')
                    ->select('class_grades.id','class_grades.name');
        $query->where('school_class_courses.school_id',$school_id);
        $query->where('school_class_courses.course_id',$course_id);

        return $query->get();
    }
}
